import 'package:example/ui/gradient.dart';
import 'package:flutter/material.dart';

class CirclePage extends StatefulWidget {
  const CirclePage({ Key? key }) : super(key: key);

  @override
  _CirclePageState createState() => _CirclePageState();
}

class _CirclePageState extends State<CirclePage> with TickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this,duration: Duration(seconds: 3));
    bool isForward = true;
    _controller.addStatusListener((status) { 
      if (status == AnimationStatus.forward){
        isForward = true;
      } else if (status == AnimationStatus.completed|| status==AnimationStatus.dismissed){
        if (isForward){
          _controller.reverse();
        }
        else {
          _controller.forward();
        }
      } else if (status == AnimationStatus.reverse){
        isForward = false;
      }
    });
    _controller.forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();

  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text('hello22'),
        ),
        body: SingleChildScrollView(child: Center(child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            AnimatedBuilder(animation: _controller, builder: (BuildContext context, Widget? child){
              return Padding(padding: const EdgeInsets.symmetric(vertical: 16),
                child: Column(children: [
                  Wrap(
                    spacing: 10,
                    runSpacing: 16,
                    children: [
                      GradientCircularProgressIndicator(radius: 50, colors: [Colors.blue,Colors.red],strokeWidth: 3,value: _controller.value,)
                    ],
                  )
                ],),
              );
            })
          ],
        ),),)
    );
  }
}